package com.jason.glidetest.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.jason.glidetest.R;
import com.jason.glidetest.bean.ImageData;

import java.util.List;


/**
 * @Author: Jason
 * @Date: 15/12/10
 * @Time: 18:39
 */

public class GifAdapter extends BaseAdapter {


    private List<ImageData> mImageDataList;
    private Context mContext;

    public GifAdapter(List<ImageData> list, Context context) {
        this.mImageDataList = list;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return mImageDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mImageDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder = null;

        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_layout, parent, false);
            viewHolder.mImageView = (ImageView) convertView.findViewById(R.id.simple_draweeview);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        ImageData imageData = mImageDataList.get(position);

        if (imageData.type == 1) {
            Glide.with(mContext).load(imageData.url).centerCrop().animate(R.anim.fade_in).into(viewHolder.mImageView);
        } else {
            Glide.with(mContext).load(imageData.url).asGif().centerCrop().animate(R.anim.fade_in).diskCacheStrategy(DiskCacheStrategy.SOURCE).into(viewHolder.mImageView);

        }




        return convertView;
    }


    private class ViewHolder {


        public ImageView mImageView;

    }



}
